﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Entity;
namespace Web.admin.InnerManage.Participants
{
    public partial class GroupList : System.Web.UI.Page
    {
        private GroupsService groupsService = new GroupsService();
        private ContestService contestsService = new ContestService();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if( !string.IsNullOrEmpty( Request.QueryString["ContestId"]))
                {
                    Rp_Bind();
                }

            }
        }
        /// <summary>
        /// repeater绑定
        /// </summary>
        protected void Rp_Bind()
        {
            RpList.DataSource = groupsService.getContestGroups(Request.QueryString["ContestId"]);
            RpList.DataBind();
        }

        protected void btn_Delete_Click(object sender, EventArgs e)
        {
            int j = 0;
            for (int i = 0; i < RpList.Items.Count; i++)
            {
                string id = ((HiddenField)RpList.Items[i].FindControl("Hf_id")).Value;
                CheckBox cb = (CheckBox)RpList.Items[i].FindControl("CbChoose");
                if (cb.Checked)
                {
                    BoGroups a = groupsService.getGroups(id);
                    a.GRO_ID = id;
                    groupsService.DeleteGroup(a);
                    j++;
                }
            }
            Response.Write("<script>alert('删除成功，共删除" + j + "条数据');window.location.href='GroupList.aspx'; </script>");
            return;
        }

            protected void RepeaterEvent(object sender,RepeaterCommandEventArgs e )
            {
                string GroupId = ((HiddenField)e.Item.FindControl("Hf_id")).Value;
                switch (e.CommandName)
                { 
                    case  "delete":
                        BoGroups model = new BoGroups();
                        model.GRO_ID = GroupId;
                        groupsService.DeleteGroup(model);
                        break;
                }
                Rp_Bind();
            }

           

            
        }

 }
